#coding=utf-8
from flask import Flask

def create_app(config=None, modules=None):
    print '#'*40
    print 'create_app'
    app = Flask(__name__)
    app.config.from_pyfile(config)
    app.debug = True

    for i in app.config['APP_MODULES']:
        if type(i) in (str, unicode):
            i = ('apps.%s' % i, 'app_%s'% i, '/%s'% i if i!='root' else '')
        _mod = __import__('%s.views' % i[0], fromlist=['*'])
        if i[2]:
            app.register_blueprint(getattr(_mod, i[1]), url_prefix=i[2])
        else:
            app.register_blueprint(getattr(_mod, i[1]))

    return app
